<template>
  <ion-page>
    <ion-header class="ion-no-border">
      <ion-toolbar>
        <ion-buttons slot="start" style="margin-top: 10px">
          <ion-back-button color="dark" text=""></ion-back-button>
        </ion-buttons>
        <ion-searchbar placeholder="查找图书" @ionChange="onSearchChange" style="margin-top: 10px"></ion-searchbar>
      </ion-toolbar>
    </ion-header>
    <ion-content :fullscreen="true">
      <ion-list-header style="font-size: medium">大家都在搜</ion-list-header>
      <p style="margin-left: 16px;">
        <ion-chip color="danger">
          <ion-icon :src="require('../../public/assets/images/fire.svg')"></ion-icon>
          <ion-label class="label1">零基础学java</ion-label>
        </ion-chip>
        <ion-chip color="danger">
          <ion-icon :src="require('../../public/assets/images/fire.svg')"></ion-icon>
          <ion-label class="label1">设计模式</ion-label>
        </ion-chip>
        <ion-chip color="danger">
          <ion-icon :src="require('../../public/assets/images/fire.svg')"></ion-icon>
          <ion-label class="label1">狂人日记</ion-label>
        </ion-chip>
        <ion-chip>
          <ion-label class="label1">凡人修仙传</ion-label>
        </ion-chip>
        <ion-chip>
          <ion-label class="label1">龙蛇演义</ion-label>
        </ion-chip>
        <ion-chip>
          <ion-label class="label1">Mysql基础</ion-label>
        </ion-chip>
      </p>
      <ion-list-header style="font-size: medium">本周热榜</ion-list-header>
      <ion-row class="row1" :key="index" v-for="(item,index) of data2">
        <ion-col class="col1" size="9">
          <div :class="index+1<=3?'div2':'div6'">{{index+1}}</div>
          <img :src="item.img">
          <div class="div3">
            <div class="div4">{{ item.name }}</div>
            <div class="div5">{{ item.author }}</div>
          </div>
        </ion-col>
        <ion-col class="col1 ion-align-items-center" style="font-size: small;">
          {{ item.search }}
        </ion-col>
      </ion-row>
    </ion-content>
  </ion-page>
</template>

<script lang="ts">
import {defineComponent} from 'vue';
import {
  IonHeader,
  IonToolbar,
  IonTitle,
  IonInput,
  IonPage,
  IonCard,
  IonItem,
  IonIcon,
  IonButton,
  IonCardContent,
  IonContent,
  IonSearchbar,
  IonCardHeader,
  IonRow,
  IonCol,
  IonSegment,
  IonSegmentButton,
  IonLabel,
  IonAvatar,
  IonImg,
  IonBackButton,
  IonButtons,
  IonListHeader,
  IonChip
} from '@ionic/vue';
import any = jasmine.any;

export default defineComponent({
  name: "SearchPage",
  components: {
    IonHeader,
    IonToolbar,
    IonTitle,
    IonInput,
    IonPage,
    IonCard,
    IonItem,
    IonIcon,
    IonButton,
    IonCardContent,
    IonContent,
    IonSearchbar,
    IonCardHeader,
    IonRow,
    IonCol,
    IonSegment,
    IonSegmentButton,
    IonLabel,
    IonAvatar,
    IonImg,
    IonBackButton,
    IonButtons,
    IonListHeader,
    IonChip
  },
  data() {
    return {
      data2:[{}],
      data1: [
        {
          name: '零基础学java',
          author: '明日科技',
          img: require('../../public/assets/images/1.jpg'),
          search:'1.2万次搜索'
        },
        {
          name: 'java从入门到精通',
          author: '明日科技',
          img: require('../../public/assets/images/2.jpg'),
          search:'0.9万次搜索'
        },
        {
          name: 'java并发编程实战',
          author: 'Brian Goetz',
          img: require('../../public/assets/images/3.jpg'),
          search:'0.8万次搜索'
        },
        {
          name: '零基础学C++',
          author: '明日科技',
          img: require('../../public/assets/images/4.jpg'),
          search:'0.5万次搜索'
        },
        {
          name: 'C#从入门到精通',
          author: '明日科技',
          img: require('../../public/assets/images/5.jpg'),
          search:'0.4万次搜索'
        },
        {
          name: '零基础学Python',
          author: '明日科技',
          img: require('../../public/assets/images/6.jpg'),
          search:'1.2万次搜索'
        },
        {
          name: '程序员数学',
          author: '保罗·奥兰德',
          img: require('../../public/assets/images/7.jpg'),
          search:'0.3万次搜索'
        },
        {
          name: '看漫画学Python',
          author: '赵大羽',
          img: require('../../public/assets/images/8.jpg'),
          search:'0.2万次搜索'
        }
      ],
    }
  },
  mounted() {
    this.data2=this.data1
  },
  methods:{
    onSearchChange(e:CustomEvent){
      if(e.detail.value===''){
        this.data2=this.data1
      }else{
        this.data2=this.data1.filter((item)=>{
          return item.name.indexOf(e.detail.value)>-1
        })
      }
    }
  },
})
</script>

<style lang="less" scoped>
.label1 {
  font-size: small
}
.row1{
  margin-top: 10px;
  margin-left: 16px;
  .col1{
    display: flex;
    img{
      width: 60px;
      height: 60px;
    }
    .div1{
      display: flex;
    }
    .div2{
      color: red;
      font-size: smaller;
      margin-right: 5px
    }
    .div3{
      display: flex;
      flex-direction: column;
      justify-content: space-around;
    }
    .div4{
      font-size: smaller
    }
    .div5{
      font-size: x-small;
      color: #8c8c8c;
    }
    .div6{
      font-size: smaller;
      margin-right: 5px
    }
  }
}
ion-toolbar{
  --background: #fff;
}
</style>
